import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 保留别人的(备份)重写底层为其添加promise处理函数
// 保留别人的方法,
const originalPush = VueRouter.prototype.push
// 给push重写,第一个参数是跳转的地址,第二个是成功的回调,第三个是失败的回调
VueRouter.prototype.push = function push(location, reject, resolve) {
  // 传了成功or失败的回调
  if (reject && resolve) {
    originalPush.call(this, location, reject, resolve)
  } else {
    // 只传了一个回调,自己手动抛出异常,为一个空的成功或失败的函数
    originalPush.call(this, location, () => { }, () => { })
  }
}

const routes = [
{
	path:'/',
	redirect:'/msite'
},
 {
	 path:'/msite',
	 component:() => import('../views/msite/index.vue'),
	 meta:{
		 isShowHeader:true
	 }
 },
 {
 	 path:'/order',
 	 component: () => import('../views/order'),
	 meta:{
	 		 isShowHeader:true
	 }
 },
 {
 	 path:'/profile',
 	 component: () => import('../views/profile'),
	 meta:{
	 		 isShowHeader:true
	 }
 },
 {
 	 path:'/search',
 	 component: () => import('../views/search'),
	 meta:{
	 		 isShowHeader:true
	 }
 },
 {
	 path:'/login',
	 component: () => import('../views/login')
 },
 {
	 path:'/userinfo',
	 component:() => import('../views/userinfo') 
 },
 {
	 path:'/shop',
	 component:() => import('../views/shop/index.vue'),
	  children:[
		  {
			  path:'/shop/goods',
			  component:() => import('../views/shop/shopGoods') 
		  },
		  {
			  path:'/shop/business',
			  component:() => import('../views/shop/shopInfo') 
		  },
		  {
			  path:'/shop/ratings',
			  component:() => import('../views/shop/shopRatings') 
		  },
		  {
			  path:'/',
			  redirect:'/shop/goods'
		  }
	  ]
 }
 
]

const router = new VueRouter({
  routes
})

export default router
